
import { OrderInfo, OrderInfoId, fenYeId } from '../../assets/axios/indent'

export default {
    namespaced: true,
    state: {
        orderListA: [],
        orderList: [],
        orderDetailInfo: {},
        list: [],
        num: 0,
        indentId: '',
    },
    mutations: {
        orderInfo(state, pal) {
            state.orderList = pal
        },
        orderInfoId(state, pal) {
            state.orderDetailInfo = pal
        },
        listChange(state, pal) {
            state.list = pal
            let count = 0
            pal.forEach(item => {
                count += item.dingdanshuliang * 1
            })
            state.num = count
        },
        AllChange(state, pal){
            state.list = state.orderList
            let count = 0
            state.orderList.forEach(item=>{
                count += item.dingdanshuliang * 1
            })
            state.num = count
            if(pal == 1){
                state.list = []
                state.num = 0
            }
        },
        getIndentId(state, pal) {
            if(pal != ''){
                state.orderListA = state.orderList.filter(item => item.dingdanhao == pal)
            }else{
                state.orderListA = []
            }
        },
        fenYeId(state, pal) {
            state.orderListA = pal
        },
        delOrder(state, pal) {
            if (state.orderListA.length == 0) {
                state.orderList = state.orderList.filter(item => {
                    return item.dingdanhao !== pal.dingdanhao 
                })
            } else {
                state.orderListA = state.orderListA.filter(item => { 
                    return item.dingdanhao !== pal.dingdanhao 
                })
            }
        }
    },
    actions: {
        orderInfo({ commit }) {
            OrderInfo().then(res => {
                commit('orderInfo', res.data)
            })

        },
        fenYeId({ commit }, pal) {
            fenYeId(pal).then(res => {
                commit('fenYeId', res.data)
            })

        },
        orderInfoId({ commit }, page) {
            OrderInfoId(page).then(res => {
                commit('orderInfoId', res.data)
            })
        }
    },
}